package com.kylin.upms.biz.web;


import com.alibaba.fastjson.JSON;
import com.kylin.upms.biz.entity.Menu;
import com.kylin.upms.biz.entity.UserSecunity;
import com.kylin.upms.biz.service.IMenuService;
import com.kylin.upms.biz.vo.ResEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2019-09-15
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IMenuService iMenuService;
    @RequestMapping("/getMenuBuUserID")
    public ResEntity getMenuBuUserID(){
        logger.info(JSON.toJSONString(SecurityContextHolder.getContext().getAuthentication().getPrincipal()));
        UserSecunity user = (UserSecunity)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<Menu> menuBuUserID = iMenuService.getMenuBuUserID(user.getUsername());
        return ResEntity.ok(menuBuUserID);
    }

    @RequestMapping(method = RequestMethod.GET,value = "/getMenuAll")
    public ResEntity getMenuAll(){
        List<Menu> menuAll = iMenuService.getMenuAll();
        return ResEntity.ok("查询成功",menuAll);
    }
    @RequestMapping(method = RequestMethod.GET,value = "/getMenuAll1")
    public ResEntity getMenuAll1(){
        List<Menu> menuAll = iMenuService.getMenuAll();
        return ResEntity.ok("查询成功",menuAll);
    }

}
